<template>
    <div class="portlet">
        <a-spin :spinning="spinning">
            <pre-textarea
                :title="$t('pro.public.footer.PrivacyPolicy')"
                :html-for-editor="htmlForEditor"
                @click="handleOKClick"
            ></pre-textarea>
        </a-spin>
    </div>
</template>

<script>
    import { getPrivacyPolicy, changePrivacyPolicy } from '../../../api/pulldown-data'
    import preTextarea from '../../../components/common/custom/PreTextarea'
    export default {
        name: "PrivacyPolicy",
        components: { preTextarea },
        data() {
            return {
                htmlForEditor: "",
                spinning: false
            }
        },
        methods: {
            handleOKClick(htmlForEditor) {
                if (!!htmlForEditor) {
                    this.spinning = true;
                    setTimeout(() => {
                        changePrivacyPolicy(htmlForEditor).then(res => {
                            let { code } = res.data
                            if (code == 200) {
                                this.$message.success(this.$t('pro.public.buttonSaveEd'));
                                this.$store.dispatch('editPrivacyPolicy', true)
                                this.initData();
                            }
                        }).finally(() => { this.spinning = false })
                    },1000)
                }
            },
            initData() {
                this.spinning = true;
                setTimeout(() => {
                    getPrivacyPolicy().then(res => {
                        let { code, data } = res.data
                        if (code == 200) {
                            this.htmlForEditor = data
                        }
                    }).finally(() => { this.spinning = false })
                }, 1000);
            }
        },
        created() {
            this.initData()
        }
    }
</script>

